﻿package ch.sfug.anim.tween.filter {
	import flash.display.DisplayObject;
	import flash.filters.BitmapFilter;
	import flash.filters.DropShadowFilter;

	import ch.sfug.anim.tween.filter.AbstractFilterTween;	

	/**
	 * animates the dropshadowfilter properties
	 * 
	 * @author mich
	 */
	public class DropShadowTween extends AbstractFilterTween {

		public function DropShadowTween( dis:DisplayObject, d:Number ) {
			super(dis, d);
		}

		protected override function getClass():Class {
			return DropShadowFilter;
		}

		protected override function shouldBeApplied():Boolean {
			var f:DropShadowFilter = DropShadowFilter(filter);
			return !( ( f.blurX == 0 && f.blurY == 0 && f.distance == 0 ) || f.alpha == 0 || f.strength == 0 );
		}

		protected override function defaultFilter():BitmapFilter {
			return new DropShadowFilter();
		}

		
		/**
		 * blurs the displayobject to a new blur value
		 */
		public function blurTo( xblur:Number, yblur:Number, easeBoth:Function = null, easeY:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(xblur) ) obj.blurX = { to: xblur, easing:easeBoth };
			if( !isNaN(yblur) ) obj.blurY = { to: yblur, easing:( easeY == null ) ? easeBoth : easeY };
			tweenFilter(obj);
		}

		/**
		 * tweens the distance value
		 */
		public function distanceTo( dist:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			obj.distance = { to:dist, easing:ease };
			tweenFilter(obj);
		}
		
		/**
		 * tweens the strength value.
		 */
		public function strengthTo( s:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			obj.strength = { to:s, easing:ease };
			tweenFilter(obj);
		}

		public function apply( distance:Number = NaN, angle:Number = NaN, color:Number = NaN, alpha:Number = NaN, blurX:Number = NaN, blurY:Number = NaN, strength:Number = NaN, quality:Number = NaN ):void {
			var f:DropShadowFilter = DropShadowFilter( filter );
			if( !isNaN( distance ) ) f.distance = distance;
			if( !isNaN( angle ) ) f.angle = angle;
			if( !isNaN( color ) ) f.color = color;
			if( !isNaN( alpha ) ) f.alpha = alpha;
			if( !isNaN( blurX ) ) f.blurX = blurX;
			if( !isNaN( blurY ) ) f.blurY = blurY;
			if( !isNaN( strength ) ) f.strength = strength;
			if( !isNaN( quality ) ) f.quality = quality;
			super.updateFilters();
		}
	}
}
